package com.example.vocab.dao;

import com.example.vocab.entity.MyWord;
import com.example.vocab.entity.Word;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface WordDao {

    @Select("select * from words order by rand() limit 100")
    List<Word> getWord();

    @Select("select * from words where frequency>700000 order by rand() limit #{e}")
    List<Word> getEasyWord(@Param("e") int e);
    @Select("select * from words where frequency>70000 and frequency<700000 order by rand() limit #{m}")
    List<Word> getMidWord(@Param("m") int m);
    @Select("select * from words where frequency<70000 order by rand() limit #{h}")
    List<Word> getHardWord(@Param("h") int h);

    @Select("select frequency from words where wid=#{wid}")
    Integer getFrequencyByWid(Integer wid);

    @Insert("insert into myword value(#{uid},#{wid})")
    Integer addMyWord(@Param("uid")int uid,@Param("wid")int wid);

    @Select("select * from myword where wid=#{wid}")
    Integer getWordByWid(@Param("wid")int wid);

    @Select("select * from myword where uid=#{uid}")
    List<MyWord> getMyWord(@Param("uid")int uid);

    @Select("select * from words where wid=#{wid}")
    Word getUnknowWord(@Param("wid")int wid);

    @Delete("delete from myword where uid=#{uid} and wid=#{wid}")
    int delMyWord(@Param("uid") int uid,@Param("wid")int wid);
}
